package com.begye.smartloan.apptest.shenhezhong.dialog

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import com.begye.smartloan.apptest.R
import com.begye.smartloan.apptest.databinding.DiaYingYongTongZhiBinding
import com.begye.smartloan.apptest.tool.addTouch

class YingYongTongZhiDialogFragment(var text: String? = null) : DialogFragment() {

    private var _binding: DiaYingYongTongZhiBinding? = null
    private val binding get() = _binding!!

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        val layout = inflater.inflate(R.layout.dia_ying_yong_tong_zhi, container, false)
        _binding = DiaYingYongTongZhiBinding.bind(layout)
        return layout
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStyle(STYLE_NO_TITLE, R.style.Theme_Bottom_Dialog)
    }

    @SuppressLint("NotifyDataSetChanged")
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        dialog?.setCancelable(true)
        dialog?.setCanceledOnTouchOutside(true)
    }

    @SuppressLint("NotifyDataSetChanged")
    override fun onStart() {
        super.onStart()
        val dialog = dialog ?: return
        val window = dialog.window ?: return

        window.attributes.gravity = Gravity.BOTTOM
        window.setLayout(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT
        )

        binding.diaYingYongTongZhiTitle.text = text

        binding.diaYingYongTongZhiConfirm.setOnClickListener {        //
            addTouch(type = "ying_yong_tong_zhi_dialog_yes_click")

            dismiss()
        }

        //
        addTouch(type = "ying_yong_tong_zhi_dialog_show")
    }

}